package com.zzyl.nursing.controller;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.nursing.domain.NursingTask;
import com.zzyl.nursing.dto.NursingTaskDto;
import com.zzyl.nursing.dto.TaskDto;
import com.zzyl.nursing.service.INursingTaskService;
import com.zzyl.nursing.vo.NursingTaskVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * 护理任务Controller
 * 
 * @author zsn
 * @date 2025-06-02
 */
@RestController
@RequestMapping("/nursing/nursingTask")
@Api(tags = "护理任务相关接口")
@Slf4j
public class NursingTaskController extends BaseController
{
    @Autowired
    private INursingTaskService nursingTaskService;

    /**
     * 获取护理任务列表
     * @param dto
     * @return
     */
    @GetMapping("/list")
    @ApiOperation(value = "获取护理任务列表")
    public TableDataInfo list(TaskDto dto)
    {
        return nursingTaskService.list(dto);
    }

    /**
     * 获取护理任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('nursing:task:query')")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取护理任务详细信息")
    public R<NursingTaskVo> getInfo(@ApiParam(value = "护理任务ID", required = true)
                                    @PathVariable("id") Long id)
    {
        return R.ok(nursingTaskService.selectNursingTaskById(id));
    }

    /**
     * 新增护理任务
     */
    @PreAuthorize("@ss.hasPermi('nursing:task:add')")
    @Log(title = "护理任务", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增护理任务")
    public AjaxResult add(@ApiParam(value = "护理任务实体", required = true) @RequestBody NursingTask nursingTask)
    {
        return toAjax(nursingTaskService.insertNursingTask(nursingTask));
    }

    /**
     * 修改护理任务
     */
    @PreAuthorize("@ss.hasPermi('nursing:task:edit')")
    @Log(title = "护理任务", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改护理任务")
    public AjaxResult edit(@ApiParam(value = "护理任务实体", required = true) @RequestBody NursingTask nursingTask)
    {
        return toAjax(nursingTaskService.updateNursingTask(nursingTask));
    }

    /**
     * 删除护理任务
     */
    @PreAuthorize("@ss.hasPermi('nursing:task:remove')")
    @Log(title = "护理任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    @ApiOperation("删除护理任务")
    public AjaxResult remove(@ApiParam(value = "要删除的数据id的数组") @PathVariable Long[] ids)
    {
        return toAjax(nursingTaskService.deleteNursingTaskByIds(ids));
    }



    /**
     * 取消任务
     */
    @PutMapping("/cancel")
    @ApiOperation(value = "取消任务")
    public AjaxResult cancelTask(@RequestBody NursingTaskDto dto){
        nursingTaskService.cancelTask(dto);
        return AjaxResult.success();
    }


    /**
     * 任务执行
     */
    @PutMapping("/do")
    @ApiOperation("任务执行")
    public AjaxResult doTask(@RequestBody NursingTaskDto dto){
        log.info("任务执行:{}",dto);
        nursingTaskService.doTask(dto);
        return AjaxResult.success();
    }


    /**
     * 任务改期
     */
    @PutMapping("/updateTime")
    @ApiOperation("任务改期")
    public AjaxResult updateTimeTask(@RequestBody NursingTaskDto dto){
        log.info("任务改期:{}",dto);
        nursingTaskService.updateTimeTask(dto);
        return AjaxResult.success();
    }



}
